import {createPinia} from "pinia" //引入pinia
import {createPersistedState} from 'pinia-plugin-persistedstate' //引入持久化插件
// import {parse,stringify} from 'zipson' //压缩

const pinia = createPinia() //创建pinia实例
pinia.use(customStorage()) //将插件添加到 pinia 实例上

/**
 * @description 自定义pinia持久化api储存方式为 uni.setStorageSync
 * @returns 
 */
function customStorage() {
    return createPersistedState({
        storage: localStorage,
        //配置压缩加密方式，默认SJON字符串
        // serializer: { 
        // 	deserialize: parse,
        // 	serialize: stringify,
        // }
    })
}

// 导入所有store
import useUserStore from './user.js'
import useDataStore from './data.js'

// 导出所有store
export {
    useUserStore,
    useDataStore
}

export default pinia //导出pinia用于main.js注册